//
//  HTTPRequestManager.m
//  AutoHome
//
//  Created by Flying meat on 9/10/15.
//  Copyright (c) 2015 CaoFeng. All rights reserved.
//

#import "HTTPRequestManager.h"
#import "NetInterface.h"
#import "AFNetworking.h"
@implementation HTTPRequestManager
+(instancetype)shareInstance
{
    
    static HTTPRequestManager *manager=nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manager=[[HTTPRequestManager alloc]init];
        
    });
    return manager;
    
    
}
//获取欢迎界面数据
-(void)getWelcomeInforSuccess:(httpSuccess)success failure:(httpFailure)failure
{
    //拼接接口
    NSString *urlString=[NSString stringWithFormat:kWelcome_Url];
  
    NSURLRequest *request=[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];

    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        if (connectionError) {
            NSLog(@"error=%@",connectionError);
        }else
        {
            
            NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
            

            NSDictionary *dicnew=dic[@"result"];
            success(dicnew);
        }
    }];
    
    
}
//最新       -c0-nt0
//新闻       -c0-nt1
//评测       -c0-nt3
//导购       -c0-nt60
//行情       -c440300-nt2  这里440300是行政编码
//用车       -c0-nt82
//技术       -c0-nt102
//文化       -c0-nt97
//改装       -c0-nt107
//游记       -c0-nt100

//#define kNew_Url kHost_And_Port@"/newslist-pm1-c%d-nt%d-p1-s30-l0.json"

//推荐界面
-(void)getRecommendInforByCt:(int)ct Nt:(int)nt success:(httpSuccess)success failure:(httpFailure)failure
{
    
    if (ct!=1000&&ct!=1001&&ct!=1002&&ct!=1003) {
        
    
        NSString *urlString=[NSString stringWithFormat:kNew_Url,ct,nt];
        NSURLRequest *request=[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
        [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
            if (connectionError) {
                failure(connectionError);
            }else
            {
                NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
                NSDictionary *dicnew=dic[@"result"];
                success(dicnew);
                
            }
        }];
    
        
        
        //推荐页面的原创视频
    }else if(ct==1000){
        
        NSString *urlString=[NSString stringWithFormat:kNew_VideoList_Url];
        NSURLRequest *request=[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
        [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
            if (connectionError) {
                failure(connectionError);
            }else
            {
                NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
                NSDictionary *dicnew=dic[@"result"];
                success(dicnew);
                
            }
        }];
        
        //说课
    }else if(ct==1001){
        NSString *urlString=[NSString stringWithFormat:kNew_ShouKeList_Url];
        NSURLRequest *request=[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
        [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
            if (connectionError) {
                failure(connectionError);
            }else
            {
                NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
                NSDictionary *dicnew=dic[@"result"];
                success(dicnew);
                
            }
        }];
        
        
    }else if (ct==1002)
    {
       
        
        NSString *urlString=[NSString stringWithFormat:kFastNew_Url];
        NSURLRequest *request=[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
        [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
            if (connectionError) {
                failure(connectionError);
            }else
            {
                NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
                NSDictionary *dicnew=dic[@"result"];
                success(dicnew);
                
            }
        }];
        
    }else if(ct==1003)
    {
        
        
        NSString *urlString=[NSString stringWithFormat:kVideoList_Url,nt];
        NSURLRequest *request=[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
        [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
            if (connectionError) {
                failure(connectionError);
            }else
            {
                NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
                NSDictionary *dicnew=dic[@"result"];
                success(dicnew);
                
            }
        }];
        
        
        
    }
   
}


#pragma mark-----论坛精选日报
-(void)getFancyTopicInforByc:(int)Fancynum success:(httpSuccess)success failure:(httpFailure)failure
{
    
    NSString *urlString=[NSString stringWithFormat:kClub_Port,Fancynum];
    NSURLRequest *request=[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        if (connectionError) {
            failure(connectionError);
        }else
        {
            NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
            NSDictionary *dicnew=dic[@"result"];
            NSArray *list=dicnew[@"list"];
            success(list);
            
        }
    }];
}

#pragma mark===========排行榜

-(void)getCarWithPaiBySt:(int)St success:(httpSuccess)success failure:(httpFailure)failure
{
    NSString *urlString=[NSString stringWithFormat:kPai_Url,St];
    NSURLRequest *request=[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        if (connectionError) {
            failure(connectionError);
        }else
        {
            NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
            NSDictionary *dicnew=dic[@"result"];
            NSArray *list=dicnew[@"list"];
            success(list);
            
            
            
        }
    }];
    
    
    
    
}


@end
